﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using fsw.Common;
using System.Data;

namespace fsw.BLL
{
    /// <summary>
    /// 管理员
    /// </summary>
    public partial class Admin
    {
        private readonly DAL.Admin dal;
        public Admin()
        {
            dal = new DAL.Admin(DTKeys.DATA_BASE_PREFIX);
        }
        #region 基本操作方法================
        /// <summary>
        /// 根据id判读是否存在
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }
        /// <summary>
        /// 根据用户名判断是否存在
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public bool Exists(string UserName)
        {
            return dal.Exists(UserName);
        }
        /// <summary>
        /// 根据用户名和密码查询是否存在
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="PassWord"></param>
        /// <returns></returns>
        public bool Exists(string UserName, string PassWord)
        {
            return dal.Exists(UserName, PassWord);
        }
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(Model.Admin model)
        {
            return dal.Add(model);
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(Model.Admin model)
        {
            return dal.Update(model);
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="strValue"></param>
        /// <returns></returns>
        public bool UpdateField(int id, string strValue)
        {
            return dal.UpdateField(id, strValue);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }
        /// <summary>
        /// 得到一个实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Model.Admin GetModel(int id)
        {
            return dal.GetModel(id);
        }
        /// <summary>
        /// 根据用户名和密码得到一个实体
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="PassWord"></param>
        /// <returns></returns>
        public Model.Admin GetModel(string UserName, string PassWord)
        {
            return dal.GetModel(UserName, PassWord);
        }
        /// <summary>
        /// 用户名和加密密码登录
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="PassWord"></param>
        /// <param name="is_encrypt"></param>
        /// <returns></returns>
        public Model.Admin GetModel(string UserName, string PassWord, bool is_encrypt)
        {
            if (is_encrypt)
            {
                PassWord = Utils.MD5(PassWord);
            }
            return dal.GetModel(UserName, PassWord);
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="Top"></param>
        /// <param name="strWhere"></param>
        /// <param name="filedOrder"></param>
        /// <returns></returns>
        public List<Model.Admin> GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 列表分页
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="strWhere"></param>
        /// <param name="filedOrder"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            return dal.GetList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
        }
        #endregion
    }
}
